# -*- coding: utf-8 -*-
"""
Created on Thu Sep 19 21:15:34 2019

@author: Administrator
"""

#定义一个图的结构
graph={
    'A':['B','C'],
    'B':['A','C','D'],
    'C':['A','B','D','E'],
    'D':['B','C','E','F'],
    'E':['C','D'],
    'F':['D']
}

# 广度优先搜索   类似于 广度遍历
def BFS(graph,start_node):
    #需要一个队列
    queue = []
    queue.append(start_node)
    seen = set()  #看是否访问过该结点
    seen.add(start_node)
    while (len(queue) > 0):
        vertex = queue.pop(0)
        nodes = graph[vertex]
        for w in nodes:
            if w not in seen:
                queue.append(w)
                seen.add(w)
        print(vertex)   

dfs_route = BFS(graph,'F')
print(dfs_route)